<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" session="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="beans.*"%>
<%@page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>VM Details</title>
<script type="text/javascript">
	function confirmBoot(VMName){
		if(confirm("Are you sure you want to boot the VM " + VMName + " ?")){
			location.href="http://"+location.hostname+":"+location.port+"/cloud/bootVM.jsp"
			+"?VMName="+VMName;
			return true;
		}
	}
	function confirmShutdown(VMName){
		if(confirm("Are you sure you want to shutdown the VM " + VMName + " ?")){
			location.href="http://"+location.hostname+":"+location.port+"/cloud/shutdownVM.jsp"
			+"?VMName="+VMName;
			return true;
		}
	}
	function confirmDelete(VMName){
		if(confirm("Are you sure you want to boot the VM " + VMName + " ?")){
			location.href="http://"+location.hostname+":"+location.port+"/cloud/deleteVM.jsp"
			+"?VMName="+VMName;
			return true;
		}
	}
</script>
</head>
<body>

<jsp:useBean id="activeUser" class="beans.UserBean" scope="session" />
<%
	ArrayList<VmInfoBean> vmInfo = VmInfoBean.getAllVmInfo(activeUser.getUsername());
	int maxIndex = vmInfo.size();
	int index = Integer.valueOf(request.getParameter("index"));
	if(index > 0&&index <= maxIndex){
		VmInfoBean vib = vmInfo.get(index-1);
		if(vib == null) out.println("Error!");
		else{
			String fullVMName = activeUser.getUsername()+"_"+vib.getVMNAME();
			String str =(Integer.valueOf(vib.getVCPU())>1)?"Cores":"Core";
%>

<center><h3>VM Details</h3></center>
<table border="2" align="center" width="300" height="80">
	<tr><td width="115">Id:</td>	<th><%=vib.getID() %></th>			</tr>
	<tr><td>Name:</td>				<th><%=vib.getVMNAME() %></th>		</tr>
	<tr><td>OS:</td>				<th><%=vib.getOS()%></th>			</tr>
	<tr><td>CPU:</td>				<th><%=vib.getVCPU() %><%=str%></th></tr>
	<tr><td>RAM:</td>				<th><%=vib.getRAM() %>G</th>		</tr>
	<tr><td>Disk Space:</td>		<th><%=vib.getDISK() %>G</th>		</tr>
	<tr><td>IP:</td> 				<th><%=vib.getIP() %></th>			</tr>
	<tr><td>Status:</td>			<th><%=vib.getStatus() %></th>		</tr>
</table>
	<p>
	<center><a href="listVMs.jsp">Go Back to VM list</a>
	<c:choose>
		<c:when test="${vib.status=='Running'}">
		<a href="javascript:void(0)" onclick='confirmBoot("<%=fullVMName%>")'>boot</a>
		</c:when>
		<c:otherwise>
		<a href="javascript:void(0)" onclick='confirmShutdown("<%=fullVMName%>")'>shutdown</a>
		</c:otherwise>
	</c:choose>
	<a href="javascript:void(0)" onclick='confirmDelete("<%=fullVMName%>")'>delete</a>
	<a href="logout.jsp">Logout</a>
	</center>
<% }} else out.println("<h3>Error!The VM does not exist!</h3>");%>

</body>
</html>